<div class="classify">
    <div class="nav">
        <div class="nav-li focus">分类管理</div>
    </div>
    <hr />
    <div class="box" style="position: relative;" event-click="{{'$Event.classify.show_menu_box'}}">
    	<div class="classify-list" style="width:59%;display:inline-block;white-space: pre-wrap;">
    		<h4>店铺分类管理</h4>
	    	<div class="nav"> | <span class="nav-item" event-click="{{'$Event.classify.nav.to_root'}}">根目录</span> / 
	    		{{#each $Cache.classify.info.parent_classify_list}}
				<span class="nav-item" event-click="{{'$Top.$Event.classify.nav.to_dir'}}">{{classify_name}}</span> / 
	    		{{/each}}\
	    		{{#if $Cache.classify.info.current_classify}}
	    		<span class="nav-item" event-click="{{'$Event.classify.nav.back'}}">{{$Cache.classify.info.current_classify.classify_name}}></span>
	    		{{/if}}
	    	</div>
	    	<div class="hr"></div>

			<div class="menu-box-static" 
				event-mouseenter="{{'$Event.classify.menu_box.lock_blur'}}" 
				event-mouseleave="{{'$Event.classify.menu_box.unlock_blur'}}">
				<!-- <button class="menu-box {{$Cache.classify.menu_box.show||'hidden'}}" ele-focus="{{$Cache.classify.menu_box.show}}" event-blur="{{'$Event.classify.hidden_menu_box'}}" style="top:{{$Cache.classify.menu_box.top}}px;left:{{$Cache.classify.menu_box.left}}px;" event-mouseenter="{{'$Event.classify.menu_box.lock_blur'}}" event-mouseleave="{{'$Event.classify.menu_box.unlock_blur'}}"> -->
				<android:paperbutton layer-num="1" event-click="{{'$Event.classify.new_classify'}}">新建文件夹（分类）</android:paperbutton>
				{{#if $Cache.classify.menu_box.pointer_classify_vms.length>=1}}
				<android:paperbutton layer-num="1" event-click="{{'$Event.classify.remove_classify'}}">删除文件夹（分类）</android:paperbutton>
				{{/if}}
				{{#if $Cache.classify.menu_box.pointer_classify_vms.length==1}}
				<!-- <android:paperbutton layer-num="1" event-click="{{'$Event.classify.rename_classify'}}">重命名</android:paperbutton>
				<android:paperbutton layer-num="1" event-click="{{'$Event.classify.reicon_classify'}}">修改图标</android:paperbutton> -->
				<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_update_classify'}}">修改属性</android:paperbutton>
					{{#if !$Cache.classify.menu_box.pointer_classify_vms.0.enable_buff}}
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_enable_buff_classify'}}">启用优惠</android:paperbutton>
					{{#else}}
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_update_buff_classify'}}">修改优惠配置</android:paperbutton>
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_disable_buff_classify'}}">停用优惠</android:paperbutton>
					{{/if}}
				{{/if}}
				{{#if $Cache.classify.menu_box.pointer_goods_vms.length>=1}}
				<android:paperbutton layer-num="1" event-click="{{'$Event.classify.remove_goods'}}">将商品移除出此文件夹</android:paperbutton>
				{{/if}}
				{{#if $Cache.classify.menu_box.pointer_classify_vms.length == 0&&$Cache.classify.info.current_classify}}
					{{#if !$Cache.classify.info.current_classify.enable_buff}}
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_enable_buff_classify'}}">启用当前文件夹优惠</android:paperbutton>
					{{#else}}
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_update_buff_classify'}}">修改当前文件夹优惠配置</android:paperbutton>
					<android:paperbutton layer-num="1" event-click="{{'$Event.classify.show_disable_buff_classify'}}">停用当前文件夹优惠</android:paperbutton>
					{{/if}}
				{{/if}}
			</div>

	    	<div class="hr"></div>

			<android:draggableArrayWrap dir="h" event-moveend="{{'$Event.classify.update_classify_index'}}">
			{{#each $Cache.classify.info.child_classify_list}}

	<android:draggableItemWrap>
		<android:draggableItem>
			<android:paperbutton
				event-dblclick="{{'$Top.$Event.classify.open_classify'}}"
				event-focus="{{'$Top.$Event.classify.store_classify_vm'}}"
				event-blur="{{'$Top.$Event.classify.release_classify_vm'}}"
				style="background-image:url({{$ParentPM.$ParentPM.$ParentPM.$CPrivate.icon_url||window._empty_img_url}});background-repeat: no-repeat;"
				class="{{icon_url&&'folder-button'}} {{#IndexOf $Top.$Cache.classify.menu_box.pointer_classify_vms, $This,' selected',''}}"
				>
				<!-- <android:paperbutton
					event-mouseenter="{{'$Top.$Event.classify.store_classify_vm'}}"
					event-mouseleave="{{'$Top.$Event.classify.release_classify_vm'}}"
					event-dblclick="{{'$Top.$Event.classify.open_classify'}}"
					style="background-image:url({{$ParentPM.$CPrivate.icon_url}})"
					class="{{icon_url&&'folder-button'}}"
					> -->
				<android:icon type="{{childClassifys.length?'file-folder':'file-folder-open'}}"></android:icon>
				<p>{{classify_name}}</p>
			</android:paperbutton>
			<icon-url-smartcrop icon-url="{{icon_url}}"></icon-url-smartcrop>
		</android:draggableItem>
	</android:draggableItemWrap>
			<script type="text/vm">
function(vm) {
	var iconImgNode = vm.getOneElementByTagName("icon-url-smartcrop");
	var buttonNode = vm.getOneElementByTagName("button");
	jSouper.onElementPropertyChange(iconImgNode, "icon-url", function(key, value) {
		if (value) {
			//将图片智能裁剪并显示成按钮背景
			require(["smartcrop-toimg"], function(smartCropToImg) {
				smartCropToImg("http://" + location.host + "/proxy?url=" + encodeURIComponent(value), {
					width: buttonNode.clientWidth,
					height: buttonNode.clientHeight
				}, function(base64) {
					vm.set("$CPrivate.icon_url", base64);
				});
			});
		}else{
			vm.set("$CPrivate.icon_url", "");
		}
	}, true)
}
			</script>
			{{/each}}
			</android:draggableArrayWrap>
<div>
			<android:draggableArrayWrap dir="h" event-moveend="{{'$Event.classify.update_classify_goods_index'}}">
			{{#each $Cache.classify.info.current_classify_goods}}
	<android:draggableItemWrap>
		<android:draggableItem>
			<android:paperbutton
				event-focus="{{'$Top.$Event.classify.store_goods_vm'}}"
				event-blur="{{'$Top.$Event.classify.release_goods_vm'}}"
				event-dblclick="{{'$Top.$Event.classify.open_goods'}}"
				class="{{#IndexOf $Top.$Cache.classify.menu_box.pointer_goods_vms, $This,' selected',''}}"
				>
				<!-- <android:paperbutton
					event-mouseenter="{{'$Top.$Event.classify.store_goods_vm'}}"
					event-mouseleave="{{'$Top.$Event.classify.release_goods_vm'}}"
					event-dblclick="{{'$Top.$Event.classify.open_goods'}}"
					> -->
				<img bind-src="{{preview_img_url}}?imageView/1/w/25/h/25">
	            <!-- <android:icon type="action-wallet-giftcard"></android:icon> -->
				<p>{{goods_name}}</p>
			</android:paperbutton>
		</android:draggableItem>
	</android:draggableItemWrap>
			{{/each}}
			</android:draggableArrayWrap>
</div>
<!-- 启用、修改BUFF -->
            <android:dialogWindow show="{{$Cache.classify.menu_box.show_enable_buff_classify||$Cache.classify.menu_box.show_update_buff_classify}}">
                <android:dialogWindow:contents>
	                <div class="classify-config-panel">
						<h2 class="{{$Cache.classify.menu_box.show_enable_buff_classify||'hidden'}}">启用<b>{{$Cache.classify.current_editting_classify.info.classify_name}}</b>优惠</h2>
	                    <h2 class="{{$Cache.classify.menu_box.show_update_buff_classify||'hidden'}}">修改<b>{{$Cache.classify.current_editting_classify.info.classify_name}}</b>优惠配置</h2>
	                    
						<android:selectSearch use-value-as-result="true" value="{{$Cache.classify.current_editting_classify.info.type}}" placeholder="请选择优惠类型" bind-input="{{'$Cache.classify.current_editting_classify.info.type'}}">
							{{#each $Top.$Cache.CLASSIFY_TYPE_array}}
							<optionItem value="{{value}}" search-data="{{value+key}}">{{key}}</optionItem>
							{{/each}}
						</android:selectSearch>

						{{#> "优惠配置面板-"+$Cache.classify.current_editting_classify.info.type,"$Cache.classify.current_editting_classify.info"}}
						<div class="hr"></div>
						<h4>会员卡特殊配置设定</h4>
						{{#each $Cache.classify.card_factory_list}}
							{{#> "classify.card_factory_list"}}
							<div class="hr"></div>
						{{/each}}

					</div>

                </android:dialogWindow:contents>
                <android:dialogWindow:actions>
                    <android:dialogWindow:action>
						{{#if $Cache.classify.menu_box.show_enable_buff_classify}}
					<android:paperbutton event-click="{{'$Event.classify.enable_buff_classify'}}">确定启用</android:paperbutton>
					{{/if}}
					{{#if $Cache.classify.menu_box.show_update_buff_classify}}
					<android:paperbutton event-click="{{'$Event.classify.update_buff_classify'}}">确定修改</android:paperbutton>
					{{/if}}
					<android:paperbutton event-click="{{'$Event.classify.cancel_config_classify'}}">取消</android:paperbutton>

                    </android:dialogWindow:action>
                </android:dialogWindow:actions>
            </android:dialogWindow>
<!-- 停用BUFF -->
            <android:dialogWindow show="{{$Cache.classify.menu_box.show_disable_buff_classify}}">
                <android:dialogWindow:contents>
					<div class="classify-config-panel">
						<h2>停用{{$Cache.classify.current_editting_classify.info.classify_name}}优惠</h2>
						<android:switch checked="{{$Cache.classify.current_editting_classify.is_child_keep_enable}}"  bind-input="{{'$Cache.classify.current_editting_classify.is_child_keep_enable'}}">保持所有无独立配置的子类目的优惠配置</android:switch>
						
					</div>
                </android:dialogWindow:contents>
                <android:dialogWindow:actions>
                    <android:dialogWindow:action>
                        <android:paperbutton event-click="{{'$Event.classify.disable_buff_classify'}}">确定停用</android:paperbutton>
						<android:paperbutton event-click="{{'$Event.classify.cancel_config_classify'}}">取消</android:paperbutton>
                    </android:dialogWindow:action>
                </android:dialogWindow:actions>
            </android:dialogWindow>
<!-- 修改分类属性 -->
            <android:dialogWindow show="{{$Cache.classify.menu_box.show_update_classify}}">
                <android:dialogWindow:contents>
	                <div class="classify-info-panel">
	                	<center>
							<img-uploader
								upload-server-url="{{config.other.upload_image}}"
								text="上传分类图标"
								bind-input-key="$Cache.classify.current_editting_classify.info.icon_url"
								url="{{$Cache.classify.current_editting_classify.info.icon_url}}"
								style="display:inline-block;"
								max-width="256"
								>
							</img-uploader>
	                	</center>
	                	<android:input value="{{$Cache.classify.current_editting_classify.info.classify_name}}" bind-input="{{'$Cache.classify.current_editting_classify.info.classify_name'}}" label="分类属性名"></android:input>
	                </div>
                </android:dialogWindow:contents>
                <android:dialogWindow:actions>
                    <android:dialogWindow:action>
                        <android:paperbutton event-click="{{'$Event.classify.confirm_update_classify'}}">确定修改</android:paperbutton>
						<android:paperbutton event-click="{{'$Event.classify.cancel_update_classify'}}">取消</android:paperbutton>
                    </android:dialogWindow:action>
                </android:dialogWindow:actions>
            </android:dialogWindow>
		</div>
       
        <div class="goods-list" style="width:40%;display:inline-block;">
            <h4>商品列表：</h4>
			{{#if $Cache.classify.card_factory_list.length}}
			<div class="card-facotry-list">
				<span class="card-facotry-item" event-click="{{'$Event.classify_to_card_factory'}}">
					公开的商品
				</span>
				{{#each $Cache.classify.card_factory_list}}
					<span class="card-facotry-item" title="{{info.intro}}" event-click="{{'$Top.$Event.classify_to_card_factory'}}" card-factory-id="{{_id}}">
						{{info.name}}
					</span>
				{{/each}}
			</div>
			{{/if}}
            <table class="paper-table">
                <thead>
                    <td width="12%" class="logo"></td>
                    <td class="name">名称</td>
                    <td width="30%" class="method">操作</td>
                </thead>
                {{#each $Cache.bus.goods_with_page_info.goods}}
                <tr>
                    <td><img bind-src="{{preview_img_url}}?imageView/1/w/25/h/25" alt="{{goods_name}}的缩略图"></td>
                    <td>{{goods_name}}</td>
                    <td>
                        <android:paperbutton class="small" layer-num="0" event-click="{{'$Top.$Event.classify.add_goods_to_classify'}}" style="font-size:large;display:{{($Top.$Cache.classify.info.current_classify._id&&classify_id!=$Top.$Cache.classify.info.current_classify._id)?'inline-block':'none'}}" title="添加到当前文件夹">
                        	<android:icon type="image-control-point"></android:icon>
                        </android:paperbutton>
                        <android:paperbutton class="small" layer-num="0" event-click="{{'$Top.$Event.classify.open_goods_classify'}}" style="font-size:large;display:{{(classify_id&&classify_id!=$Top.$Cache.classify.info.current_classify._id)?'inline-block':'none'}}" title="打开所在文件夹">
                        	<android:icon type="action-pageview"></android:icon>
                        </android:paperbutton>
                    </td>
                </tr>
                {{/each}}
            </table>
			<pagecut
				num="{{$Cache.bus.goods_with_page_info.num}}"
				page="{{$Cache.bus.goods_with_page_info.page}}"
				total-page="{{$Cache.bus.goods_with_page_info.total_page}}"
			></pagecut>
        </div>
    </div>
</div>
<xmp type="template" name="classify.card_factory_list">
	<h5>{{info.name}}</h5>
	<android:switch>是否启用优惠</android:switch>
	{{#if $Private.enable_buff}}
		<android:selectSearch use-value-as-result="true" placeholder="请选择优惠类型">
			{{#each $Top.$Cache.CLASSIFY_TYPE_array}}
			<optionItem value="{{value}}" search-data="{{value+key}}">{{key}}</optionItem>
			{{/each}}
		</android:selectSearch>
		<div class="优惠-config">
			{{#> "优惠配置面板-"+$Private.type, "$Top.$Cache.classify.current_editting_classify.info.card_factory_config_list."+$Caller.$Index}}
		</div>
	{{/if}}
	<script type="text/vm">
	function  xx(vm) {
		var cardFactoryNode = vm.getOneElementByTagName("classify:cardFactory");
		var selectsearchNode = vm.getOneElementByTagName("selectsearchwrap");
		var switchNode = vm.getOneElementByTagName("android:switch");
		var switchInputNode = switchNode.getElementsByTagName("input")[0];

		vm.addAttr(selectsearchNode, {
			"index": "{{$Index}}"
		});
		var data_source_key;
		jSouper.onElementPropertyChange(selectsearchNode, "index", function(key, value) {
			if (value && isFinite(value)) {
				data_source_key = "$Top.$Cache.classify.current_editting_classify.info.card_factory_config_list." + vm.get("$Index");

				vm.set("$Private.data_source_key", data_source_key);

				vm.addAttr(selectsearchNode, {
					"value": "{{" + data_source_key + ".type}}",
					"bind-input": "{{'"+ data_source_key + ".type'}}"
				});
				vm.addAttr(switchInputNode, {
					"checked": "{{" + data_source_key + ".enable_buff}}",
					"input": "{{'"+ data_source_key + ".enable_buff'}}"
				});
			}
		});
		jSouper.onElementPropertyChange(selectsearchNode, "value", function(key, value) {
			vm.set("$Private.type", value)
		}, true);
		jSouper.onElementPropertyChange(switchInputNode, "checked", function(key, value) {
			vm.set("$Private.enable_buff", value)
		}, true);
	}
	</script>
</xmp>
